home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / osr5 / sco / scripts / mail / addrem next >
Encoding:
Korn shell script  |  1997-08-26  |  3.3 KB  |  122 lines

  1. #!/bin/ksh
  2. # @(#) addrem.ksh 2.0 96/11/13
  3. # addrem: write to reminder file or mail reminder
  4. # 91/05/21 john h. dubois iii (john@armory.com)
  5. # 91/05/28 changed to use hostname instead of hard-coded host name.
  6. # 91/07/22 changed to use $REMIND if first arg is not "me" and
  7. #          does not have a ! or @ in it.
  8. # 92/11/08 Read from input if no reminder text given.
  9. # 93/07/23 Changed name from remind to addrem to avoid conflict;
  10. #          changed 'me' special name to '.'
  11. # 94/01/21 Prepend date.
  12. # 94/04/23 Use .addrem
  13. # 96/01/20 Use $UHOME if set.
  14. # 96/11/13 Use option flags instead of basing local/remote on 1st argument.
  15.  
  16. remsubj=%%remind%%
  17. name=${0##*/}
  18. Usage="Syntax: $name [-hl] [-m<mail-address>] reminder-line"
  19. local=false
  20. oREMIND=$REMIND
  21. rFile=$HOME/.addrem
  22. verbose=true
  23. if [ -f "$rFile" -a -r "$rFile" ]; then
  24.     . "$rFile"
  25. fi
  26. [ -n "$oREMIND" ] && REMIND=$OREMIND
  27. [ "$QUIET" = 1 ] && verbose=false
  28.  
  29. while getopts hlm:q opt; do
  30.     case $opt in
  31.     h)
  32.     print -r -- \
  33. "$name: write to reminder file or mail reminder.
  34. $Usage
  35. If -l is given, reminder-line is is appended to the file .reminder in the
  36. invoking user's home directory.  If not, it is sent via email to the recipient
  37. specified by the REMIND environment variable.  REMIND can also be set in a file
  38. named .addrem, which should be in the invoking user's home directory or in the
  39. directory specified by the environment variable UHOME.  In the .addrem file,
  40. place a line that has the form:
  41. REMIND=user
  42. The subject of the mail will be \"$remsubj\".  The current date will
  43. be prepended to the reminder line in the body of the mail.  The reminder line
  44. does not need to be quoted unless it contains characters special to the shell.
  45. To make reminders in this format that are mailed to you automatically be put
  46. into your .reminder file instead of showing up in your mailbox, add the
  47. following line to your .maildelivery file:
  48. Subject    %%remind%% pipe    A /usr/local/bin/procrem
  49. $Usage
  50. Options:
  51. -h: Print this help.
  52. -l: Write to local .reminders file.
  53. -q: Operate quietly.  Set QUIET=1 in .addrem to make this the default.
  54. -v: Operate verbosely (default).
  55. -m<mail-address>: Mail reminder to <mail-address> instead of using the REMIND
  56.     variable."
  57.     exit 0
  58.     ;;
  59.     q)
  60.     verbose=false
  61.     ;;
  62.     v)
  63.     verbose=true
  64.     ;;
  65.     l)
  66.     local=true
  67.     ;;
  68.     m)
  69.     REMIND=$OPTARG
  70.     ;;
  71.     ?)
  72.     print -r -u2 "Use -h for help."
  73.     exit 1
  74.     ;;
  75.     esac
  76. done
  77.  
  78. # remove args that were options
  79. let OPTIND=OPTIND-1
  80. shift $OPTIND
  81.  
  82. if [ "$1" = . ]; then
  83.     print -ru2 -- "$name: Obsolete invokation; use -l instead of '.'.
  84. Use -h for help.  Exiting."
  85.     exit 1
  86. fi
  87.  
  88. if [ $local = false -a -z "$REMIND" ]; then
  89.     print -ru2 -- "$name: No destination (REMIND not set and -l not given).
  90. Use -h for help.  Exiting."
  91.     exit 1
  92. fi
  93.  
  94. # dirmail: invoke execmail directly.
  95. # usage: dirmail <subject> <destination> <text>
  96. dirmail() {
  97.     echo \
  98. "From: $USER@`hostname` ($NAME)
  99. To: $2
  100. Subject: $1
  101. Date: `date`
  102.  
  103. $3" | /usr/lib/mail/execmail "$2"
  104. }
  105.  
  106. if [ $# -lt 1 ]; then
  107.     [ -t 0 ] && echo "Enter reminder text; end with ^D."
  108.     text="`cat`"
  109. else
  110.     text=$*
  111. fi
  112.  
  113. text="`date +%y/%m/%d` $text"
  114.  
  115. if $local; then 
  116.     print -r -- "$text" >> $HOME/.reminder 
  117.     $verbose && print -r -- "$name: Reminder added to .reminder file."
  118. else
  119.     dirmail "$remsubj" "$REMIND" "$text"
  120.     $verbose && print -r -- "$name: Sent reminder to $REMIND."
  121. fi
  122.